<?php

namespace Common\Repository;

use Common\Model\Admin;

class AdminRepository extends BaseRepository
{
    /**
     * 返回模型名称
     */
    public function baseModel()
    {
        return new Admin();
    }

    /**
     * 获取列表数据-含分页
     *
     * @param array $arr_option
     * @return mixed
     */
    public function extendGetList($arr_option = [])
    {
        $model = new Admin();
        $arr_option = $model->configOption($arr_option);
        if (isset($arr_option['whereHas'])) {
            $model = $model->whereHas('admin_roles', function ($query) use ($arr_option) {
                $query->where('roles_id', $arr_option['whereHas']);
            });
        }

        return $model->with($arr_option['with'])
            ->where($arr_option['where'])
            ->select($arr_option['field'])
            ->orderBy($arr_option['order']['key'], $arr_option['order']['value'])
            ->paginate($arr_option['limit'])
            ->toArray();
    }

}